define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            $(".btn-add").data("area", ["100%", "100%"]); //添加
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'buchang/diaodu/index' + location.search,
                    add_url: 'buchang/diaodu/add',
                    // edit_url: 'buchang/diaodu/edit',
                    // del_url: 'buchang/diaodu/del',
                    multi_url: 'buchang/diaodu/multi',
                    import_url: 'buchang/diaodu/import',
                    table: 'diaodu',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                fixedColumns: true,
                fixedRightNumber: 1,
                columns: [
                    [
                        {checkbox: true},
                        // {field: 'id', title: __('Id')},
                        // {field: 'gs_type', title: __('Gs_type'),operate: false},
                        {field: 'baoan_id', title: __('Baoan_id'), operate: 'LIKE'},
                        {
                            field: 'baoan_time',
                            title: __('Baoan_time'),
                            operate: 'RANGE',
                            addclass: 'datetimerange',
                            autocomplete: false,
                            formatter: Table.api.formatter.datetime
                        },
                        {
                            field: 'chuxian_time',
                            title: __('Chuxian_time'),
                            operate: 'RANGE',
                            addclass: 'datetimerange',
                            autocomplete: false,
                            formatter: Table.api.formatter.datetime
                        },
                        {field: 'phone', title: __('Phone'),operate: false},
                        {field: 'tong_number', title: __('Tong_number'), operate: 'LIKE'},
                        {field: 'car_num', title: __('Car_num'), operate: 'LIKE'},
                        {field: 'car_vin', title: __('Car_vin'), operate: 'LIKE'},
                        {field: 'learned_name', title: __('Learned_name'), operate: 'LIKE'},
                        {
                            field: 'yw_hetong_time',
                            title: __('Yw_hetong_time'),
                            operate: 'RANGE',
                            addclass: 'datetimerange',
                            autocomplete: false,
                            formatter: Table.api.formatter.datetime,datetimeFormat: "YYYY-MM-DD"
                        },
                        {
                            field: 'plan_endtime',
                            title: __('Plan_endtime'),
                            operate: 'RANGE',
                            addclass: 'datetimerange',
                            autocomplete: false,
                            formatter: Table.api.formatter.datetime,datetimeFormat: "YYYY-MM-DD"
                        },
                        {field: 'chakan_ren', title: __('Chakan_ren'), operate: 'LIKE'},
                        {field: 'buchang_money', title: __('Buchang_money'), operate: false},
                        {field: 'baoan_status', title: __('Baoan_status'),
                            searchList: {
                                0: __('未结案'),
                                1: __('已结案'),
                            },formatter: Table.api.formatter.label
                        },
                        {
                            field: 'operate',
                            title: __('Operate'),
                            table: table,
                            events: Table.api.events.operate,
                            formatter: Table.api.formatter.operate,
                            buttons: [
                                {
                                    name: 'details',
                                    text: '调度',
                                    classname: 'btn btn-info btn-xs btn-dialog',
                                    icon: '',
                                    url: 'buchang/diaodu/diaodu',
                                    extend: 'data-area=["100%","100%"]',
                                    visible: function (row) {
                                        //返回true时按钮显示,返回false隐藏
                                        return true;
                                    }
                                }
                            ]
                        }
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        diaodu: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
